package com.sjgtw.cloud.system.api.fallbackfactory;

import com.sjgtw.cloud.common.core.domain.R;
import com.sjgtw.cloud.system.api.domain.SysDictDataVO;
import com.sjgtw.cloud.system.api.domain.SysDictTypeVO;
import com.sjgtw.cloud.system.api.service.RemoteDictService;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>Title: 数据字典服务异常处理</p>
 * <p>Description: </p>
 * @author Admin
 * @date 2021-4-7
 */
@Component
public class RemoteDictFallbackFactory implements FallbackFactory<RemoteDictService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteDictFallbackFactory.class);

    @Override
    public RemoteDictService create(Throwable throwable)
    {
        log.error("部门服务调用失败:{}", throwable.getMessage());
        return new RemoteDictService(){
            @Override
            public R<List<SysDictTypeVO>> listNoAuth(SysDictTypeVO sysDictType) {
                return  R.fail("字典查询失败");
            }

            @Override
            public R<List<SysDictDataVO>> dataInfoNoAuth(SysDictDataVO sysDictData) {
                return  R.fail("字典详情查询失败");
            }
        };
    }
}
